﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using Barbar.Colonization.Core.Localization.XmlProvider;
using System.Threading;

namespace Barbar.Colonization.Core.Localization {
  public class Translator {
    private Hashtable m_Dictionary = new Hashtable();
    private static object SyncRoot = new object();
    private static Translator TranslatorInstance;

    private Translator() {
      // TODO: loading factories should be configurable
      XmlTranslatorFactory factory = new XmlTranslatorFactory();
      factory.FillTranslator(this);
    }

    public string GetText(string code) {
      int lcid = Thread.CurrentThread.CurrentCulture.LCID;
      TranslatorKey key = new TranslatorKey(code, lcid);
      return (string)m_Dictionary[key];
    }

    public static Translator Instance {
      get {
        lock(SyncRoot) {
          if (TranslatorInstance == null)
            TranslatorInstance = new Translator();
          return TranslatorInstance;
        }
      }
    }

    internal void Add(TranslatorKey key, string value) {
      m_Dictionary.Add(key, value);
    }
  }
}
